home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2002 January / maximum-cd-2002-01.iso / Files / Mechwarrior 4 Mapping / MW4Editor.exe / content / ABLScripts / GenericScripts / Generic_Turret.abl < prev    next >
Encoding:
Text File  |  2001-07-16  |  5.3 KB  |  186 lines

  1.  
  2. //------------------------------------------------------------------
  3. // NOTE: The fsm name below MUST be changed in order for the
  4. // script to be considered a unique entity!
  5.  
  6. fsm Generic_Turret : integer;
  7.  
  8.  
  9. //------------------------------------------------------------------
  10.  
  11. // Generic_Turret:
  12. //   This shoots anything that comes near, but never moves.
  13. //   It can be used for turrets.
  14.  
  15. //------------------------------------------------------------------
  16.  
  17.  
  18.  
  19. //------------------------------------------------------------------
  20. //     Constants
  21. //------------------------------------------------------------------
  22.  
  23.     const
  24.         #include_ <content\ABLScripts\mwconst.abi>
  25.  
  26. //------------------------------------------------------------------
  27. //     Types
  28. //------------------------------------------------------------------
  29.  
  30.     type
  31.         #include_ <content\ABLScripts\mwtype.abi>
  32.     
  33.  
  34. //------------------------------------------------------------------
  35. //     Variables
  36. //------------------------------------------------------------------
  37.  
  38.     var
  39.         static integer            attackRange;        // At what range do I start shooting?
  40.         static integer            withdrawRange;        // At what range do I stop attacking?
  41.  
  42.         static ObjectID            turretTower;        // My control tower: if destroyed, I stop firing
  43.                                                     
  44.         static integer            piloting;            // Piloting skill
  45.         static integer            gunnery;            // Gunnery skill/chance to hit
  46.         static real                minDelay;            // Minimum amount of time I will wait between shots once a weapon is reloaded
  47.         static real                maxDelay;            // Maximum amount of time I will wait between shots once a weapon is reloaded
  48.         static integer             eliteLevel;            // Elite level.  This helps determine tactics, defensive manuevers, opportunity fire
  49.                                                     // and other things.  It indicates a general level of combat experience.
  50.  
  51.          static integer            isShotRadius;        // How far away from me will I detect an enemy shot?
  52.         static integer            findTypes;            // What kind of enemies to look for
  53.  
  54.         static integer             attackSound;        // The attack sound I play when I first attack
  55.         static integer             deathSound;            // The sound I play when I die
  56.         
  57.         static integer            mood;                // My default mood.
  58.  
  59.         static integer            takeOffDistance;    // My take-off distance if I'm an airplane (ignored if not an airplane)
  60.  
  61. //------------------------------------------------------------------
  62. //     Init: my initialization function
  63. //------------------------------------------------------------------
  64.  
  65. function Init;
  66.     code
  67.         // script-specific variables
  68.         attackRange        = 500;
  69.         withdrawRange    = attackRange * 3 / 2;
  70.  
  71.         turretTower        = NO_UNIT;
  72.  
  73.         takeOffDistance    = 150;
  74.  
  75.         // driver settings
  76.         piloting        = 50;
  77.         gunnery            = 30;
  78.         minDelay        = 1.5;
  79.         maxDelay        = 3.0;
  80.         eliteLevel        = 30;
  81.         isShotRadius    = 120;
  82.         attackSound        = -1; // no sound
  83.         deathSound        = -1; // no sound
  84.         mood            = NEUTRAL_START;
  85.         findTypes        = FT_DEFAULT;
  86.  
  87. endfunction;
  88.  
  89. //------------------------------------------------------------------
  90. //    StartState: my initial state
  91. //------------------------------------------------------------------
  92.  
  93. state StartState;
  94.  
  95.     code
  96.         SetFiringDelay            (ME,minDelay,maxDelay);
  97.         SetIgnoreFriendlyFire    (ME,true);
  98.         SetIsShotRadius            (ME,isshotradius);
  99.         SetEntropyMood            (ME,mood);
  100.         SetCurMood                (ME,mood);
  101.         SetSkillLevel            (ME,piloting,gunnery,elitelevel);
  102.                 
  103.         if (orderTakeOff(takeOffDistance) == true) then
  104.             trans WaitState;
  105.         endif;
  106.  
  107. endstate;            
  108.  
  109. //------------------------------------------------------------------
  110. //    WaitState: wait for someone to come near
  111. //------------------------------------------------------------------
  112.  
  113. state WaitState;
  114.     code
  115.         if (FindEnemy(attackRange,findTypes)) then
  116.             trans AttackState;
  117.         endif;
  118.  
  119.         if (turretTower <> NO_UNIT) then
  120.             if (IsDead(turretTower) == true) then
  121.                 trans TowerGoneState;
  122.             endif;
  123.         endif;
  124.  
  125.         SetSensorVisibility(ME,FALSE);
  126.         OrderMoveLookOut;
  127. endstate;
  128.  
  129. //------------------------------------------------------------------
  130. //    AttackState: let's see what's around, and destroy it
  131. //------------------------------------------------------------------
  132.  
  133. state AttackState;
  134.     code
  135.         if (LeaveAttackState(withdrawRange)) then
  136.             OrderStopAttacking;
  137.             SetTarget(ME,NO_UNIT);
  138.             trans WaitState;
  139.         endif;
  140.  
  141.         if (turretTower <> NO_UNIT) then
  142.             if (IsDead(turretTower) == true) then
  143.                 trans TowerGoneState;
  144.             endif;
  145.         endif;
  146.  
  147.         if (attackSound <> -1) then    
  148.             PlaySoundOnce(attackSound);
  149.         endif;
  150.  
  151.         SetSensorVisibility(ME,TRUE);
  152.         OrderAttackTactic(TACTIC_SHOOT_ONLY,true);
  153.  
  154. endstate;
  155.  
  156. //------------------------------------------------------------------
  157. //    TowerGoneState: my control tower is destroyed; I can do nothing
  158. //------------------------------------------------------------------
  159.  
  160. state TowerGoneState;
  161.     code
  162.         SetTarget(ME,NO_UNIT);
  163.         OrderStopAttacking;
  164.         ClearMoveOrder(ME);
  165.         SetTargetDesirability(ME,-1);
  166.         SetSensorVisibility(ME,FALSE);
  167. endstate;
  168.  
  169. //------------------------------------------------------------------
  170. //    DeadState: OK, I kicked the bucket.
  171. //------------------------------------------------------------------
  172.  
  173. state DeadState;
  174.     code
  175.         if (deathSound <> -1) then    
  176.             PlaySoundOnce(deathSound);
  177.         endif;        
  178.  
  179.         orderDie;
  180.  
  181. endstate;
  182.  
  183.  
  184. endfsm.
  185.  
  186.